#!/bin/bash
category="SENSORS"

sensorslog='/tmp/sensors.log'
cycle=${1:-'600'}

interval=60

useTime=0
> $sensorslog

while (( useTime <= cycle)) 
do
    /usr/bin/sensors >> $sensorslog
    sleep $interval
    useTime=`expr $useTime + $interval`
done


cpu_max=`cat $sensorslog  |grep 'Package id 0:'  |awk  '{print $4}' | sed 's/+//g' | sed 's/°C//g' |sort -nr | head -1`
cpu_min=`cat $sensorslog  |grep 'Package id 0:'  |awk  '{print $4}' | sed 's/+//g' | sed 's/°C//g' |sort -n | head -1`
power_max=`cat $sensorslog  |grep 'power1:'  |awk  '{print $2}' | sort -nr | head -1`
power_min=`cat $sensorslog  |grep 'power1:'  |awk  '{print $2}' | sort -n | head -1`

echo "category=${category};temperature_max=${cpu_max};temperature_min=${cpu_min};power_max=${power_max};power_min=${power_min}"
